package view;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.border.TitledBorder;

import controller.employee.CheckLogin;

public class Login extends JFrame {

	private static final long serialVersionUID = 1L;
	private JButton btnLogin;
	private JButton btnCancel;
	private JLabel lblPass;
	private JLabel lblAccount;
	private JPanel panelLogin;
	private JPasswordField tfPass;
	private JSeparator jSeparator1;
	private JTextField tfAccount;
	private JPanel panelTitle;
	private final ImagePanel imagePane;
	private final ImagePanel title;
	public Login login;
	
	private static Login instance;
	
	public static Login getInstance(){
		if(instance == null)
			return instance = new Login();
		return instance;
	}
	
	
	private Login() {
		initComponents();
		imagePane = new ImagePanel();
		imagePane.setSize(170, 190);
		// imagePane.setOpaque(false);
		getContentPane().add(imagePane);
		imagePane.setBounds(30, 130, 240, 190);
		imagePane.repaint();
		title = new ImagePanel("icon/logo.png");
		panelTitle.add(title);
		title.setBounds(0, 0, panelTitle.getWidth(), panelTitle.getHeight());
		// title.setOpaque(false);
		title.repaint();

		getContentPane().setBackground(Color.white);

	}

	private void initComponents() {

		panelLogin = new JPanel();
		lblPass = new JLabel();
		lblAccount = new JLabel();
		tfAccount = new JTextField();
		btnLogin = new JButton();
		btnCancel = new JButton();
		tfPass = new JPasswordField();
		jSeparator1 = new JSeparator();
		panelTitle = new JPanel();

		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setTitle("Login");
		setBackground(new java.awt.Color(255, 255, 255));
		setBounds(new java.awt.Rectangle(0, 0, 0, 0));
		setPreferredSize(new java.awt.Dimension(700, 400));
		setResizable(false);
		getContentPane().setLayout(null);

		panelLogin.setBorder(BorderFactory.createTitledBorder(null, "Login",
				TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 1,
						24)));
		panelLogin.setOpaque(false);
		panelLogin.setLayout(null);

		lblPass.setFont(new java.awt.Font("Calibri", 0, 20));
		lblPass.setText("Password:");
		panelLogin.add(lblPass);
		lblPass.setBounds(20, 80, 90, 30);

		lblAccount.setFont(new java.awt.Font("Calibri", 0, 20));
		lblAccount.setText("Account:");
		panelLogin.add(lblAccount);
		lblAccount.setBounds(20, 40, 90, 23);

		tfAccount.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jTextField1ActionPerformed(evt);
			}
		});
		panelLogin.add(tfAccount);
		tfAccount.setBounds(130, 40, 200, 30);

		btnLogin.setFont(new java.awt.Font("Calibri", 1, 18));
		btnLogin.setForeground(new java.awt.Color(0, 102, 204));
		btnLogin.setText("Login");
		btnLogin.setIcon(new ImageIcon("icon/login.png"));
		btnLogin.addActionListener(new CheckLogin(this));

		btnLogin.setHorizontalAlignment(SwingConstants.LEFT);
		btnLogin.setMargin(new java.awt.Insets(2, 5, 2, 5));
		btnLogin.setOpaque(false);
		btnLogin.setVerifyInputWhenFocusTarget(false);
		panelLogin.add(btnLogin);
		btnLogin.setBounds(130, 120, 90, 30);

		btnCancel.setFont(new java.awt.Font("Calibri", 1, 18));
		btnCancel.setForeground(new java.awt.Color(0, 102, 204));
		btnCancel.setText("Cancel");
		btnCancel.setIcon(new ImageIcon("icon/logout.png"));
		btnCancel.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				if (JOptionPane.showConfirmDialog(login,
						"Do you want to exit?", "Exit",
						JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
					System.exit(0);
				} else {

				}

			}
		});

		btnCancel.setIconTextGap(2);
		btnCancel.setMargin(new java.awt.Insets(2, 1, 2, 1));
		btnCancel.setOpaque(false);
		panelLogin.add(btnCancel);
		btnCancel.setBounds(220, 120, 90, 30);
		panelLogin.add(tfPass);
		tfPass.setBounds(130, 80, 200, 30);

		getContentPane().add(panelLogin);
		panelLogin.setBounds(310, 150, 360, 170);

		jSeparator1.setBackground(new java.awt.Color(0, 102, 255));
		jSeparator1.setMinimumSize(new java.awt.Dimension(700, 30));
		jSeparator1.setName("");
		getContentPane().add(jSeparator1);
		jSeparator1.setBounds(0, 340, 700, 10);

		panelTitle.setOpaque(false);
		panelTitle.setLayout(null);
		getContentPane().add(panelTitle);
		panelTitle.setBounds(230, 40, 240, 60);

		pack();
	}

	public JButton getBtnLogin() {
		return btnLogin;
	}

	public void setBtnLogin(JButton btnLogin) {
		this.btnLogin = btnLogin;
	}

	public JButton getBtnCancel() {
		return btnCancel;
	}

	public void setBtnCancel(JButton btnCancel) {
		this.btnCancel = btnCancel;
	}

	public JPanel getPanelLogin() {
		return panelLogin;
	}

	public void setPanelLogin(JPanel panelLogin) {
		this.panelLogin = panelLogin;
	}

	public JPasswordField getTfPass() {
		return tfPass;
	}

	public void setTfPass(JPasswordField tfPass) {
		this.tfPass = tfPass;
	}

	public JTextField getTfAccount() {
		return tfAccount;
	}

	public void setTfAccount(JTextField tfAccount) {
		this.tfAccount = tfAccount;
	}

	public JPanel getPanelTitle() {
		return panelTitle;
	}

	public void setPanelTitle(JPanel panelTitle) {
		this.panelTitle = panelTitle;
	}

	private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {

	}

	public static void main(String args[]) {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				Login.getInstance().setLocationRelativeTo(null);
				Login.getInstance().setVisible(true);
			}
		});
	}

}
